#-*-coding: utf-8 -*-
#/usr/bin/python

import ssh5
import MySQLdb

def add_member(member_name):
    host = raw_input("host: ")
    port = raw_input("port: ")
    username = raw_input("username: ")
    password = raw_input("password: ")
    cmd = raw_input("command: ")
    dict2 = {"host": host, "username": username, "port": port, "password": password, "cmd": cmd}
    conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="devops")
    cursor = conn.cursor()
    sql = "insert into member(host, username, port, password) values('%s', '%s', %s, '%s')" % (dict2["host"], dict2["username"], dict2["port"], dict2["password"])
    cursor.execute(sql)
    print "add success!!!"
    cursor.close()
    conn.close()

    ssh5.ssh5(dict2["host"], int(dict2["port"]), dict2["username"], dict2["password"], dict2["cmd"])

def add_group(groupName):
    conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="devops")
    cursor = conn.cursor()
    sql = "insert into groups(gname) values %s" % groupName
    cursor.execute(sql)
    cursor.close()
    conn.close()
    
dict_count = 0
while True:
    dict_count = dict_count + 1
    member =  "dict" + str(dict_count)
    print member
    add_member(member)
    status = raw_input("type any key for continue, type 'quit' for exit: ")
    if status == "quit":
        print "Bye..."
        break
